/**
 * Created by xlzd on 2016/01/15.
 */

function submitwhat(id) {
    var $form = $('#search-form');
    $form.find('input[name=querytype]').val(id);
    $form.submit();
}

$(function() {
    $('#collect-doc').on('click', function (evt) {
        evt.preventDefault();
        $btn = $(this);
        var mode = $btn.attr('data-mode');
        //alert('mode:' + mode)
        var sid = $('input[name=sid]').val();
        var span = $btn.find('span');
        $.ajax({
            method: 'POST',
            url: '/collect/' + sid,
            contentType: 'application/json;charset=utf8',
            data: JSON.stringify({
                method: mode
            })
        })
            .done(function (data, status, jqXhr) {
                if (mode == 'collect'){
                    $btn.attr('data-mode', 'no-collect');

                    $btn.removeClass('btn-primary')
                        .addClass('btn-default');

                    span.removeClass('glyphicon-plus')
                        .addClass('glyphicon-heart');
                    span.html('已收藏');
                } else {
                    $btn.attr('data-mode', 'collect');

                    $btn.removeClass('btn-default')
                        .addClass('btn-primary');

                    span.removeClass('glyphicon-heart')
                        .addClass('glyphicon-plus');
                    span.html('加入收藏');
                }
            })
            .fail(function (jqXhr, reason) {});
    });
});


function change(){
    var toggle = $('#toggle');
    var switch_a = $('#switch-a');

    var search_div = $('#search');
    var high_div = $('#high-search');

    if (toggle.val() == 'search'){
        search_div.css('display', 'none');
        high_div.css('display', 'block');
        switch_a.html('普通搜索');
        toggle.val('high-search');
    } else {
        search_div.css('display', 'block');
        high_div.css('display', 'none');
        switch_a.html('高级搜索');
        toggle.val('search');
    }
}